//--------------------音频--------------------//
$(function(){
    var audio = $('#myaudio').get(0);
    //播放暂停控制
    $('#playPause').click(function(){
        //监听音频播放时间并更新进度条
        audio.addEventListener('timeupdate',updateProgress,false);
        //监听播放完成事件
        audio.addEventListener('ended',audioEnded,false);

        //改变暂停/播放icon
        if(audio.paused){
            audio.play();
            $('.icon-btn').removeClass('icon-play').addClass('icon-pause');
            $(".audio-img").addClass("reverseRotataZ");
            
        } else{
            audio.pause();
            $('.icon-btn').removeClass('icon-pause').addClass('icon-play');
            $(".audio-img").removeClass("reverseRotataZ");                        
        }
    })

    //读取视频长度,设置页面时长显示-loadedmetadata:指定视频/音频（audio/video）的元数据加载后触发
    //audio.duration 获取音频的时长，单位为秒
    $('#myaudio').on("loadedmetadata",function () {
        $('#audioTime').text(transTime(this.duration));
    });

})
//转换音频时长显示
function transTime(time) {
    var duration = parseInt(time);
    var minute = parseInt(duration/60);
    var sec = duration%60+'';
    var isM0 = ':';
    if(minute == 0){
        minute = '00';
    }else if(minute < 10 ){
        minute = '0'+minute;
    }
    if(sec.length == 1){
        sec = '0'+sec;
    }
    return minute+isM0+sec
}

//更新进度条
function updateProgress() {
    var audio =document.getElementsByTagName('audio')[0];
    var value = Math.round((Math.floor(audio.currentTime) / Math.floor(audio.duration)) * 100, 0);
    $('.played-time').html(transTime(audio.currentTime));
}
//播放完成
function audioEnded() {
    var audio =document.getElementsByTagName('audio')[0];
    audio.currentTime=0;
    audio.pause();
    $('.play-pause>i').removeClass('icon-pause').addClass('icon-play');
    $(".audio-img").removeClass("reverseRotataZ");     
}


//--------------------视频--------------------//
$(function(){
	var video=document.getElementById("myvideo");
	var novideo=$("#myvideo").find("source").attr("src");
	if(novideo==""){
		$(".noVideoTab").show();
	}
	$('body').on('click', "#videoPlay", function() {
		$("#videoImg").hide();
		$("#videoShadow").hide();	
		$("#videoPlay").hide();	
	    video.play();
	});	
})
